package com.weibo.login.dao.imp;

import java.sql.ResultSet;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.weibo.common.CommonUtil;
import com.weibo.common.DB;
import com.weibo.login.dao.LoginDao;
import com.weibo.sql.SqlFile;
import com.weibo.user.User;

public class LoginDaoImp implements LoginDao {
	private static Logger logger = Logger.getLogger(LoginDaoImp.class);

	@Override
	public User getLoginUser(HttpSession session) {
		// TODO Auto-generated method stub
		User user = (User)session.getAttribute("login_user");
		return user;
	}

	@Override
	public User validate(String username, String password) {
		// TODO Auto-generated method stub
		User user = null;
		ResultSet rs = DB.plsqlExecOut_rs(SqlFile.LOGIN_USER_VALIDATE, username,password);
		List<User> list = CommonUtil.getUserList_ByRs(rs);
		if(list.size()>0){
			user = list.get(0);
		}
		return user;
	}

	@Override
	public boolean updateLoginDate(String user_id) {
		// TODO Auto-generated method stub
		return DB.plsqlExec(SqlFile.LOIGN_UPDATE_LOGINTIME, user_id);
	}
	

}
